<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/common/common.jsp" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> 
  <head>
    <base href="<%=basePath%>" />
    <title>Menu Management</title>
    <script type="text/javascript">
		var path = "<%=basePath%>";
	</script>
	<meta http-equiv="pragma" content="no-cache" />
	<meta http-equiv="cache-control" content="no-cache" />
	<meta http-equiv="expires" content="0" />    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3" />
	<meta http-equiv="description" content="This is my page" />
	<link rel="stylesheet" type="text/css" href="<%=basePath%>basic/css/content.css" />
	<!-- 页面特效 -->
	<jsp:include page="/beshs/res-refer/page-effect-reference.jsp" />
	<!-- 系统通用资源 -->
	<jsp:include page="/resources/resource-refer/common-resource-reference.jsp" />
	<!-- 表单校验 -->
	<jsp:include page="/resources/resource-refer/component-validform-reference.jsp" />
	<!-- 用户访问菜单路径 -->
	<jsp:include page="/resources/usertrace/common-uservisit-reference.jsp" />
  </head>
  <script type="text/javascript">
  	function submitForm() {
  		var menuID = "<s:property value='menuID' />";
  		var parentMenuID = "<s:property value='parentMenuID' />";
  		var menuName = $("input[name='menuName']").val();
  		var menuAction = $("input[name='menuAction']").val();
  		var menuIcon = $("input[name='menuIcon']").val();
  		var orderID = $("input[name='orderID']").val();
  		var remark = $("textarea[name='remark']").val();
  		$.getJSON(path+"basic/menuActionJson!saveOrUpdateMenu.do?date="+new Date(), {
  			"menu.id": menuID,
  			"menu.menuName": $.trim(menuName),
  			"menu.menuAction": $.trim(menuAction),
  			"menu.menuIcon": $.trim(menuIcon),
  			"menu.orderID": orderID,
  			"menu.remark": $.trim(remark),
  			"menu.parentID": parentMenuID
  		}, function(data){
  			if(data.success) {
  				Dialog.alert("Successful Operation！", function(){
  					var index = parent.layer.getFrameIndex(window.name)
					parent.window.frames["menuMgr"].location = path + "basic/jsp/menuMgrTree.jsp?date="+new Date();
  					parent.window.frames["tempSwitch"].location = path + "basic/menuAction!queryByParentMenuID.do?parentMenuID="+parentMenuID;
  					parent.layer.close(index);
  				});
  			} else {
  				//alert("系统异常，请联系管理员！");
  				Dialog.alert("System error, please contact adminitrator！");
  			}
  		});
  	}
  	
  	$(function(){
		$("form[name='menuForm']").Validform({
			btnSubmit: "input[name='submit']",
			btnReset: "input[name='reset']",
			tiptype: function(msg, o, cssctl){
				//msg：提示信息;
				//o:{obj:*,type:*,curform:*}, obj指向的是当前验证的表单元素（或表单对象），type指示提示的状态，值为1、2、3、4， 1：正在检测/提交数据，2：通过验证，3：验证失败，4：提示ignore状态, curform为当前form对象;
				//cssctl:内置的提示信息样式控制函数，该函数需传入两个参数：显示提示信息的对象 和 当前提示的状态（既形参o中的type）;
				if(!o.obj.is("form")){//验证表单元素时o.obj为该表单元素，全部验证通过提交表单时o.obj为该表单对象;
					var objtip=o.obj.siblings(".Validform_checktip");
					cssctl(objtip,o.type);
					objtip.text(msg);
				} else {
					var objtip=o.obj.find("#msgdemo");
					cssctl(objtip,o.type);
					objtip.text(msg);
				}
			},
			postonce: true, //开启二次提交防御，在数据成功提交后，表单将不能再继续提交
			showAllError: true, //提交表单时所有错误提示信息都会显示
			ajaxPost:true,
			beforeSubmit: function(curform) { //在验证成功后，表单提交前执行的函数，curform参数是当前表单对象
				submitForm();
				return true; //这里明确return false的话表单将不会提交
			}
		});
  	});
  </script>
  <body>
    <div class="content_all">
  		<!--导航条-->
  		<div class="insertinfo_table">
      		<form action="#" name="menuForm"><table width="100%" border="0" cellspacing="0" cellpadding="0">
        		<tr>
          			<th>Menu Name：</th>
          			<td><input name="menuName" type="text" class="s_input" value="<s:property value='menu.menuName' />" 
          					datatype="/^[\-0-9a-zA-Z\u4e00-\u9fa5]{2,64}$/" sucmsg="Menu Name Verification Passed！" nullmsg="Please enter menu name！" errormsg="Menu Name only can be composed of letters,numbers and dashes within 2~64 characters！" />
            			&nbsp;<span style="color:#FF0000;">*</span>
            			<div class="Validform_checktip">Menu Name only can be composed of letters,numbers and dashes within 2~64 characters！</div></td>
        		</tr>
        		<tr>
          			<th>Function Link：</th>
          			<td><input name="menuAction" type="text" class="s_input" value="<s:property value='menu.menuAction' />" 
          					datatype="/^[a-zA-Z\/][0-9a-zA-Z\-\_\/\.\!\&\?]*[0-9a-zA-Z]$/, *4-128" ignore="ignore" errormsg="" />
          				<div class="Validform_checktip">Formate：basic/menuAction!query.do</div></td>
        		</tr>
        		<tr>
          			<th>Icon Link：</th>
          			<td><input name="menuIcon" type="text" class="s_input" value="<s:property value='menu.menuIcon' />" 
          					datatype="/^[a-zA-Z\/][0-9a-zA-Z\-\_\/\.\!\&\?]*[0-9a-zA-Z]$/, *4-128" ignore="ignore" errormsg="" />
          				<div class="Validform_checktip">Formate：basic/images/image.jpg</div></td>
        		</tr>
        		<tr>
          			<th>Display Sequence：</th>
          			<td><input name="orderID" type="text" class="s_input" value="<s:property value='menu.orderID' />" 
          					datatype="n1-10" errormsg="！" ignore="ignore" />
          				<div class="Validform_checktip"></div></td>
        		</tr>
        		<tr>
          			<th>Remark：</th>
          			<td><textarea name="remark" cols="45" rows="3"
          					datatype="*1-80" ignore="ignore" errormsg="请填写有效内容，控制在1-80个字符！" >
          					<s:property value='menu.remark' /></textarea>
          				<div class="Validform_checktip"></div></td>
        		</tr>
        		<tr>
          			<td style="border:none;"></td>
          			<td style="border:none;">
          				<input name="submit" type="button" value="Submit" class="s_btn" />
            			<input name="reset" type="reset" value="Reset" class="s_btn"/></td>
        		</tr>
      		</table></form>
  		</div>
	</div>
	<div class="clear"></div>
  </body>
</html>
